/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_thrift.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/17 by jikw                                 */
/*******************************************************************/

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <pthread.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/thrift/config.h"

#include "t_tbinary/t_thrift_tbinary_detect/t_thrift_tbinary_detect.h"
#include "t_tbinary/t_thrift_tbinary_req_analyze/t_thrift_tbinary_req_analyze.h"
#include "t_tbinary/t_thrift_tbinary_resp_analyze/t_thrift_tbinary_resp_analyze.h"
#include "t_tbinary/t__req_parse/t__req_parse.h"
#include "t_tbinary/t__resp_parse/t__resp_parse.h"
#include "t_tbinary/t__tbinary_readobject/t__tbinary_readobject.h"
#include "t_tbinary/t__tbinary_readobject_twice/t__tbinary_readobject_twice.h"

#include "t_tcompact/t_tcompact.h"
static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    //t_thrift_tbinary_detect
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_thrift_tbinary_detect);
    //t_thrift_tbinary_req_analyze
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_thrift_tbinary_req_analyze);
    //t_thrift_tbinary_resp_analyze
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_thrift_tbinary_resp_analyze);
    //t__req_parse
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__req_parse);
    //t__resp_parse
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__resp_parse);
    //t__tbinary_readobject
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__tbinary_readobject);
    //t__tbinary_readobject_twice
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__tbinary_readobject_twice);

    //t_tcompact
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_direction_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite___read_varint32);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite___read_varint64);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readByte);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readI16);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readI32);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readI64);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readDouble);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readString);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_readBinary);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_message_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_field_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_struct_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_map_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_list_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_bool_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_byte_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_i16_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_i32_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_i64_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_double_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_string_begin);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_tcompact_read_binary_begin);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();

    fr_slab_destroy();

    return 0;
}
